package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.dto.AssignRoleDTO;
import net.wanho.dto.UserInfoDTO;
import net.wanho.po.AuthInfo;
import net.wanho.po.UserInfo;
import net.wanho.service.AuthInfoService;
import net.wanho.service.UserInfoService;
import net.wanho.vo.PageInfo;
import net.wanho.vo.R;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2024-10-21 16:18
 * Description：<描述>
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserInfoController {

    private final AuthInfoService authInfoService;
    private final UserInfoService userInfoService;

    @GetMapping("/auth-list")
    public R  findMenus(){
        List<AuthInfo> list = authInfoService.findMenus();
        return R.success(list);
    }

    @GetMapping("/user-list")
    public R getUserList(@RequestParam(required = false, defaultValue = "1") int pageNum,
                         @RequestParam(required = false, defaultValue = "5") int pageSize,
                         UserInfoDTO userInfoDTO){
        PageInfo<UserInfo> pageInfo =  userInfoService.listPage(pageNum, pageSize, userInfoDTO);
        return R.success(pageInfo);
    }

    @PutMapping("/assignRole")
    public R assignRole(@RequestBody AssignRoleDTO assignRoleDTO){
        userInfoService.assignRole(assignRoleDTO);
        return R.success("角色分配成功！");
    }

    @GetMapping("/exportTable")
    public R exportTable(@RequestParam(required = false, defaultValue = "1") int pageNum,
                        @RequestParam(required = false, defaultValue = "5") int pageSize,
                        UserInfoDTO userInfoDTO){
        PageInfo<UserInfo> pageInfo =  userInfoService.listPage(pageNum, pageSize, userInfoDTO);
        return R.success(pageInfo.getResultList());
    }

}
